--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit 7b0658b197a366cadfb04294f2278a0afd0e80c6
Parents : b8ab1ca
Author : Mark Qvist <mark@unsigned.io>
Date : 2025-11-22T00:04:56+01:00
Handle GC1109 LNA gain variance properly
Changes
4 files changed, 36 insertions(+), 7 deletions(-)
Diff
diff --git a/Config.h b/Config.h
index 29e1f4f..2afbd09 100644
--- a/Config.h
+++ b/Config.h
@@ -110,7 +110,9 @@
#define CSMA_CW_PER_BAND_WINDOWS 15
#define CSMA_BAND_1_MAX_AIRTIME 7
#define CSMA_BAND_N_MIN_AIRTIME 85
- #define CSMA_INFR_THRESHOLD_DB 12
+ #define CSMA_INFR_THRESHOLD_DB 6
+ #define CSMA_RFENV_RECAL_MS 2500
+ #define CSMA_RFENV_RECAL_LIMIT_DB -83
bool interference_detected = false;
bool avoid_interference = true;
int csma_slot_ms = CSMA_SLOT_MIN_MS;
diff --git a/Makefile b/Makefile
index 8ba24a9..8cbbe6b 100644
--- a/Makefile
+++ b/Makefile
@@ -211,8 +211,8 @@ upload-heltec32_v4:
arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3
@sleep 1
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin)
- @sleep 3
- python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
+ #@sleep 3
+ #python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
upload-tdeck:
arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3
diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino
index 75fcffb..5d2eb6a 100644
--- a/RNode_Firmware.ino
+++ b/RNode_Firmware.ino
@@ -1383,6 +1383,8 @@ void update_noise_floor() {
#define LED_ID_TRIG 16
uint8_t led_id_filter = 0;
+uint32_t interference_start = 0;
+bool interference_persists = false;
void update_modem_status() {
#if MCU_VARIANT == MCU_ESP32
portENTER_CRITICAL(&update_lock);
@@ -1404,6 +1406,19 @@ void update_modem_status() {
if (interference_detected) { if (led_id_filter < LED_ID_TRIG) { led_id_filter += 1; } }
else { if (led_id_filter > 0) {led_id_filter -= 1; } }
+ // Handle potential false interference detection due to
+ // LNA recalibration, antenna swap, moving into new RF
+ // environment or similar.
+ if (interference_detected && current_rssi < CSMA_RFENV_RECAL_LIMIT_DB) {
+ if (!interference_persists) {
+ interference_persists = true; interference_start = millis();
+ } else {
+ if (millis()-interference_start >= CSMA_RFENV_RECAL_MS) { noise_floor_sampled = false; interference_persists = false; }
+ }
+ } else {
+ interference_persists = false;
+ }
+
if (carrier_detected) { dcd = true; } else { dcd = false; }
dcd_led = dcd;
diff --git a/sx126x.cpp b/sx126x.cpp
index c1e7c20..c67a4df 100644
--- a/sx126x.cpp
+++ b/sx126x.cpp
@@ -356,8 +356,13 @@ int sx126x::begin(long frequency) {
// Keep PA CPS low until actual
// transmit. Does it save power?
// Who knows? Will have to measure.
+ // Note from the future: Nope.
+ // Power consumption is the same,
+ // and turning it on and off is
+ // not something that it likes.
+ // Keeping it high for now.
pinMode(LORA_PA_CPS, OUTPUT);
- digitalWrite(LORA_PA_CPS, LOW);
+ digitalWrite(LORA_PA_CPS, HIGH);
// On Heltec V4, the PA CTX pin
// is driven by the SX1262 DIO2
@@ -375,7 +380,10 @@ int sx126x::beginPacket(int implicitHeader) {
#if HAS_LORA_PA
#if LORA_PA_GC1109
// Enable PA CPS for transmit
- digitalWrite(LORA_PA_CPS, HIGH);
+ // digitalWrite(LORA_PA_CPS, HIGH);
+ // Disabled since we're keeping it
+ // on permanently as long as the
+ // radio is powered up.
#endif
#endif
@@ -476,7 +484,6 @@ uint8_t sx126x::packetRssiRaw() {
}
int ISR_VECT sx126x::packetRssi() {
- // TODO: May need more calculations here
uint8_t buf[3] = {0};
executeOpcodeRead(OP_PACKET_STATUS_6X, buf, 3);
int pkt_rssi = -buf[0] / 2;
@@ -590,7 +597,12 @@ void sx126x::receive(int size) {
#if HAS_LORA_PA
#if LORA_PA_GC1109
// Disable PA CPS for receive
- digitalWrite(LORA_PA_CPS, LOW);
+ // digitalWrite(LORA_PA_CPS, LOW);
+ // That turned out to be a bad idea.
+ // The LNA goes wonky if it's toggled
+ // on and off too quickly. We'll keep
+ // it on permanently, as long as the
+ // radio is powered up.
#endif
#endif
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────